import $api from '@/http/interface'

// 路由守卫
const beforeEnter = (to, from, next) => {
  let token = window.localStorage.getItem('user-token')
  if (!token) {
    window.location.href = $api.oauthPath()
    return
  }
  next()
}
const routes = [
  {
    path: '/new-law-express',
    name: 'new-law-express',
    redirect: '/new-law-express/list',
    meta: { layout: 'admin', title: '新法速递' },
    beforeEnter: beforeEnter,
    component: () => import('@/modules/new-law-express/views/new-law-express'),
    children: [
      {
        path: 'list',
        name: 'new-law-express-list',
        meta: { layout: 'admin', title: '' },
        beforeEnter: beforeEnter,
        component: () => import('@/modules/new-law-express/views/new-law-express-list')
      },
      {
        path: 'detail/:id',
        name: 'new-law-express-detail',
        meta: { layout: 'admin', title: '正文阅览' },
        beforeEnter: beforeEnter,
        component: () => import('@/modules/new-law-express/views/new-law-express-detail')
      }
    ]
  }
]

function mount () {
  this.$router.addRoutes(routes)
}

export default {
  mount
}
